% Statiscal analyzis of reversals and omegas
clear all

load ('/Users/anapereira/Dropbox/Matlab/data analyzis group/matlab data/reversals and omegas/all experiments 13.11.2019/N2 and RRF3 experiments/rev_ome_joinexperiments_all_ZC2834_13_11_2019.mat');%matrix to store the data

data = rev_ome_joinexperiments_all_ZC2834_13_11_2019; 

data {11,2,1} = 'P-value';
data {11,3,1} = 'CorMC';% value corrected for multiple comparisons; 
data {11,6,1} = 'P-value';
data {11,7,1} = 'CorMC';% value corrected for multiple comparisons; 
data {11,10,1} = 'P-value';
data {11,11,1} = 'CorMC';% value corrected for multiple comparisons; 
data {11,14,1} = 'P-value';
data {11,15,1} = 'CorMC';% value corrected for multiple comparisons; 
data {11,16,1} = 'P-value';
data {11,17,1} = 'CorMC';% value corrected for multiple comparisons;
data {11,18,1} = 'P-value';
data {11,19,1} = 'CorMC';% value corrected for multiple comparisons; 

data {12,1,1} = 'ManU choiceOP';%comparison of OPF1 and PAF1 that choose OP
data {13,1,1} = 'ManU choicePA';%comparison of OPF1 and PAF1 that choose PA 
data {14,1,1} = 'ManU OPw';% comparison between OPF1 that choose either OP or PA;
data {15,1,1} = 'ManU PAw';% comparison between PAF1 that choose either OP or PA;

data {16,1,1} = 't-test choiceOP';%comparison of OPF1 and PAF1 that choose OP
data {17,1,1} = 't-test choicePA';%comparison of OPF1 and PAF1 that choose PA 
data {18,1,1} = 't-test OPw';% comparison between OPF1 that choose either OP or PA;
data {19,1,1} = 't-test PAw';% comparison between PAF1 that choose either OP or PA;

%% Make the statistical comparisons
% ranksum is the equivalent to ManU test - independent samples non normaly
% distributed 

%% REVERSALS SECOND

%F1s that choose OP stim
OPtoOPrev_sec = data {2,2,1};
PAtoOPrev_sec = data {2,4,1};
nOPtoOPrev_sec = size (OPtoOPrev_sec, 1); %to confirm we are collecting the right data
nPAtoOPrev_sec = size (PAtoOPrev_sec, 1); %to confirm we are collecting the right data
[p1,h1] = ranksum(OPtoOPrev_sec ,PAtoOPrev_sec);
[ht1,pt1] = ttest2(OPtoOPrev_sec ,PAtoOPrev_sec);
data {12,2,1} = p1;
data {16,2,1} = pt1;

%F1s that choose PA stim
OPtoPArev_sec = data {2,3,1};
PAtoPArev_sec = data {2,5,1};
nOPtoPArev_sec = size (OPtoPArev_sec, 1);
nPAtoPArev_sec = size (PAtoPArev_sec , 1);
[p2,h2] = ranksum(OPtoPArev_sec,PAtoPArev_sec);
[ht2,pt2] = ttest2(OPtoPArev_sec,PAtoPArev_sec);
data {13,2,1} = p2;
data {17,2,1} = pt2;

%F1s from OP mothers
OPtoOPrev_sec = data {2,2,1};
OPtoPArev_sec = data {2,3,1};
nOPtoOPrev_sec = size (OPtoOPrev_sec, 1);
nOPtoPArev_sec = size (OPtoPArev_sec, 1);
[p3,h3] = ranksum(OPtoOPrev_sec,OPtoPArev_sec);
[ht3,pt3] = ttest2(OPtoOPrev_sec,OPtoPArev_sec);
data {14,2,1} = p3;
data {18,2,1} = pt3;

%F1s from PA mothers
PAtoOPrev_sec = data {2,4,1};
PAtoPArev_sec = data {2,5,1};
nPAtoOPrev_sec= size (PAtoOPrev_sec, 1);
nPAtoPArev_sec = size (PAtoPArev_sec, 1);
[p4,h4] = ranksum(PAtoOPrev_sec,PAtoPArev_sec);
[ht4,pt4] = ttest2(PAtoOPrev_sec,PAtoPArev_sec);
data {15,2,1} = p4;
data {19,2,1} = pt4;

% OP progeny vs PA progeny
OPprogrev_sec = data {2,18,1};
PAprogrev_sec = data {2,19,1};

nOPprogrev_sec= size (OPprogrev_sec, 1);
nPAprogrev_sec = size (PAprogrev_sec, 1);
[p17,h17] = ranksum(OPprogrev_sec,PAprogrev_sec);
[ht17,pt17] = ttest2(OPprogrev_sec,PAprogrev_sec);
data {12,18,1} = p4;
data {16,18,1} = pt4;


%% REVERSALS DURATION

%F1s that choose OP stim
OPtoOPrevdur = data {2,6,1};
PAtoOPrevdur = data {2,8,1};
nOPtoOPrevdur = size (OPtoOPrevdur, 1); %to confirm we are collecting the right data
nPAtoOPrevdur = size (PAtoOPrevdur, 1); %to confirm we are collecting the right data
[p5,h5] = ranksum(OPtoOPrevdur,PAtoOPrevdur);
[ht5,pt5] = ttest2(OPtoOPrevdur,PAtoOPrevdur);
data {12,6,1} = p5;
data {16,6,1} = pt5;

%F1s that choose PA stim
OPtoPArevdur  = data {2,7,1};
PAtoPArevdur  = data {2,9,1};
nOPtoPArevdur  = size (OPtoPArevdur , 1);
nPAtoPArevdur  = size (PAtoPArevdur , 1);
[p6,h6] = ranksum(OPtoPArevdur ,PAtoPArevdur);
[ht6,pt6] = ttest2(OPtoPArevdur ,PAtoPArevdur);
data {13,6,1} = p6;
data {17,6,1} = pt6;

%F1s from OP mothers
OPtoOPrevdur = data {2,6,1};
OPtoPArevdur = data {2,7,1};
nOPtoOPrevdur = size (OPtoOPrevdur, 1);
nOPtoPArevdur = size (OPtoPArevdur, 1);
[p7,h7] = ranksum(OPtoOPrevdur,OPtoPArevdur);
[ht7,pt7] = ttest2(OPtoOPrevdur,OPtoPArevdur);
data {14,6,1} = p7;
data {18,6,1} = pt7;

%F1s from PA mothers
PAtoOPrevdur = data {2,8,1};
PAtoPArevdur = data {2,9,1};
nPAtoOPrevdur = size (PAtoOPrevdur, 1);
nPAtoPArevdur = size (PAtoPArevdur, 1);
[p8,h8] = ranksum(PAtoOPrevdur,PAtoPArevdur);
[ht8,pt8] = ttest2(PAtoOPrevdur,PAtoPArevdur);
data {15,6,1} = p8;
data {19,6,1} = pt8;

% OP progeny vs PA progeny_revdur
OPprogrev_dur = data {2,20,1};
PAprogrev_dur = data {2,21,1};

nOPprogrev_dur= size (OPprogrev_dur, 1);
nPAprogrev_dur = size (PAprogrev_dur, 1);
[p18,h18] = ranksum(OPprogrev_dur,PAprogrev_dur);
[ht18,pt18] = ttest2(OPprogrev_dur,PAprogrev_dur);
data {12,20,1} = p18;
data {16,20,1} = pt18;
%% OMEGAS PER SECOND

%F1s that choose OP stim
OPtoOPomesec = data {2,10,1};
PAtoOPomesec = data {2,12,1};
nOPtoOPomesec = size (OPtoOPomesec, 1); %to confirm we are collecting the right data
nPAtoOPomesec = size (PAtoOPomesec, 1); %to confirm we are collecting the right data
[p9,h9] = ranksum(OPtoOPomesec,PAtoOPomesec);
[ht9,pt9] = ttest2(OPtoOPomesec,PAtoOPomesec);
data {12,10,1} = p9;
data {16,10,1} = pt9;

%F1s that choose PA stim
OPtoPAomesec = data {2,11,1};
PAtoPAomesec = data {2,13,1};
nOPtoPAomesec = size (OPtoPAomesec, 1);
nPAtoPAomesec = size (PAtoPAomesec, 1);
[p10,h10] = ranksum(OPtoPAomesec,PAtoPAomesec);
[ht10,pt10] = ttest2(OPtoPAomesec,PAtoPAomesec);
data {13,10,1} = p10;
data {17,10,1} = pt10;

%F1s from OP mothers
OPtoOPomesec = data {2,10,1};
OPtoPAomesec = data {2,11,1};
nOPtoOPomesec = size (OPtoOPomesec, 1);
nOPtoPAomesec = size (OPtoPAomesec, 1);
[p11,h11] = ranksum(OPtoOPomesec,OPtoPAomesec);
[ht11,pt11] = ttest2(OPtoOPomesec,OPtoPAomesec);
data {14,10,1} = p11;
data {18,10,1} = pt11;

%F1s from PA mothers
PAtoOPomesec = data {2,12,1};
PAtoPAomesec = data {2,13,1};
nPAtoOPomesec = size (PAtoOPomesec, 1);
nPAtoPAomesec = size (PAtoPAomesec, 1);
[p12,h12] = ranksum(PAtoOPomesec,PAtoPAomesec);
[ht12,pt12] = ttest2(PAtoOPomesec,PAtoPAomesec);
data {15,10,1} = p12;
data {19,10,1} = pt12;

% OP progeny vs PA progeny_omegas/sec
OPprogome_sec = data {2,22,1};
PAprogome_sec = data {2,23,1};

nOPprogome_sec= size (OPprogome_sec, 1);
nPAprogome_sec = size (PAprogome_sec, 1);
[p19,h19] = ranksum(OPprogome_sec,PAprogome_sec);
[ht19,pt19] = ttest2(OPprogome_sec,PAprogome_sec);
data {12,22,1} = p19;
data {16,22,1} = pt19;

%% OMEGAS DURATION
%F1s that choose OP stim
OPtoOPomedur = data {2,14,1};
PAtoOPomedur = data {2,16,1};
nOPtoOPomedur = size (OPtoOPomedur, 1); %to confirm we are collecting the right data
nPAtoOPomedur = size (PAtoOPomedur, 1); %to confirm we are collecting the right data
[p13,h13] = ranksum(OPtoOPomedur,PAtoOPomedur);
[ht13,pt13] = ttest2(OPtoOPomedur,PAtoOPomedur);
data {12,14,1} = p13;
data {16,14,1} = pt13;

%F1s that choose PA stim
OPtoPAomedur = data {2,15,1};
PAtoPAomedur = data {2,17,1};
nOPtoPAomedur = size (OPtoPAomedur, 1);
nPAtoPAomedur = size (PAtoPAomedur, 1);
[p14,h14] = ranksum(OPtoPAomedur,PAtoPAomedur);
[ht14,pt14] = ttest2(OPtoPAomedur,PAtoPAomedur);
data {13,14,1} = p14;
data {17,14,1} = pt14;

%F1s from OP mothers
OPtoOPomedur = data {2,14,1};
OPtoPAomedur = data {2,15,1};
nOPtoOPomedur = size (OPtoOPomedur, 1);
nOPtoPAomedur = size (OPtoPAomedur, 1);
[p15,h15] = ranksum(OPtoOPomedur,OPtoPAomedur);
[ht15,pt15] = ttest2(OPtoOPomedur,OPtoPAomedur);
data {14,14,1} = p15;
data {18,14,1} = pt15;

%F1s from PA mothers
PAtoOPomedur = data {2,16,1};%F1s from PA mothers
PAtoPAomedur = data {2,17,1};
nPAtoOPomedur = size (PAtoOPomedur, 1);
nPAtoPAomedur = size (PAtoPAomedur, 1);
[p16,h16] = ranksum(PAtoOPomedur,PAtoPAomedur);
[ht16,pt16] = ttest2(PAtoOPomedur,PAtoPAomedur);
data {15,14,1} = p16; 
data {19,14,1} = pt16;

% OP progeny vs PA progeny_omegas/sec
OPprogome_dur = data {2,24,1};
PAprogome_dur = data {2,25,1};

nOPprogome_dur= size (OPprogome_dur, 1);
nPAprogome_dur = size (PAprogome_dur, 1);
[p20,h20] = ranksum(OPprogome_dur,PAprogome_dur);
[ht20,pt20] = ttest2(OPprogome_dur,PAprogome_dur);
data {12,24,1} = p20;
data {16,24,1} = pt20;

rev_ome_joinexperiments_all_ZC2834_13_11_2019 = data;